//修改结缘信息
let { love } = require("./love_schema.js");
//修改用户信息
let { user } = require("../login/sign_schma.js");
//发送邮件
let { system } = require("../system_msg/system_schema.js");
module.exports = {
    changeLove: function (req, res, err) {
        let changeData = req.query;
        console.log(changeData, "数据");
        let status = changeData.status;
        if (status == 3) {
            love.updateOne({ user: changeData.sendUser, toUser: changeData.addressee }, { $set: { status } }).then((loveData) => {
                console.log(loveData, "结缘");
                //修改用户信息
                let userArr = [changeData.sendUser, changeData.addressee];
                userArr.forEach((item, index) => {
                    let projectId = index == 0 ? 1 : 0;
                    user.updateOne({ user: item }, { $set: { luckMeet: true, toUser: userArr[projectId] } }).then((userData) => {
                        console.log(userData, "用户");
                        // 发送邮件
                        let title = "系统消息";
                        let content = `你与用户${userArr[projectId]}的已正式结缘、在数据管理中双方的数据可以共享啦。`;
                        let sendUser = "情缘工作组";
                        let addressee = item;
                        let core = 1;
                        let reply = "no";
                        let createTime = req.query.createTime;
                        system.create({ sendUser, addressee, core, title, content, reply, createTime }).then((emailData) => {
                            console.log(emailData, "邮件");
                            res.send(true);
                        })
                    })
                })
            })
        }
    }
}